<p>This tutorial assumes that you have created a DNS A record for <code>trilium.yourdomain.com</code> that
  you want to use for your Trilium server.</p>
<h2>Docker setup</h2>
<p>Download docker image and create container</p><pre><code class="language-text-x-trilium-auto"> docker pull triliumnext/trilium:[VERSION]
 docker create --name trilium -t -p 127.0.0.1:8080:8080 -v ~/trilium-data:/home/node/trilium-data triliumnext/trilium:[VERSION]</code></pre>
<h2>Configuring the Apache proxy</h2>
<ol>
  <li>
    <p>Enable apache proxy modules</p><pre><code class="language-text-x-trilium-auto"> a2enmod ssl
 a2enmod proxy
 a2enmod proxy_http
 a2enmod proxy_wstunnel</code></pre>
  </li>
  <li>
    <p>Create a new let's encrypt certificate</p><pre><code class="language-text-x-trilium-auto"> sudo certbot certonly -d trilium.mydomain.com</code></pre>
    <p>Choose standalone (2) and note the location of the created certificates
      (typically /etc/letsencrypt/live/...)</p>
  </li>
  <li>
    <p>Create a new virtual host file for apache (you may want to use <code>apachectl -S</code> to
      determine the server root location, mine is /etc/apache2)</p><pre><code class="language-text-x-trilium-auto"> sudo nano /etc/apache2/sites-available/trilium.yourdomain.com.conf</code></pre>
    <p>Paste (and customize) the following text into the configuration file</p><pre><code class="language-text-x-trilium-auto"> 
     ServerName http://trilium.yourdomain.com
     RewriteEngine on
         RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
 
 
     ServerName https://trilium.yourdomain.com
     RewriteEngine On
     RewriteCond %{HTTP:Connection} Upgrade [NC]
     RewriteCond %{HTTP:Upgrade} websocket [NC]
     RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
     AllowEncodedSlashes NoDecode
     ProxyPass / http://localhost:8080/ nocanon
     ProxyPassReverse / http://localhost:8080/
     SSLCertificateFile /etc/letsencrypt/live/trilium.yourdomain.com/fullchain.pem
     SSLCertificateKeyFile /etc/letsencrypt/live/trilium.yourdomain.com/privkey.pem
     Include /etc/letsencrypt/options-ssl-apache.conf
 </code></pre>
  </li>
  <li>
    <p>Enable the virtual host with <code>sudo a2ensite trilium.yourdomain.com.conf</code>
    </p>
  </li>
  <li>
    <p>Reload apache2 with <code>sudo systemctl reload apache2</code>
    </p>
  </li>
</ol>
<h2>Configuring the trusted proxy</h2>
<p>After setting up a reverse proxy, make sure to configure the&nbsp;<a class="reference-link"
  href="#root/_help_LLzSMXACKhUs">Trusted proxy</a>.</p>
<h2>Setup the systemd service to start up the server</h2>
<p>Create and enable a systemd service to start the docker container on boot</p>
<ol>
  <li>
    <p>Create a new empty file called <code>/lib/systemd/system/trilium.service</code> with
      the contents</p><pre><code class="language-text-x-trilium-auto"> [Unit]
 Description=Trilium Server
 Requires=docker.service
 After=docker.service

 [Service]
 Restart=always
 ExecStart=/usr/bin/docker start -a trilium
 ExecStop=/usr/bin/docker stop -t 2 trilium

 [Install]
 WantedBy=local.target</code></pre>
  </li>
  <li>
    <p>Install, enable and start service</p><pre><code class="language-text-x-trilium-auto"> sudo systemctl daemon-reload
 sudo systemctl enable trilium.service
 sudo systemctl start trilium.service</code></pre>
  </li>
</ol>